<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>

    console.log((-5) % 3);

    function info() { year = 1999; };
    info();
    console.log(year)

    // var age = prompt("请输入您的年龄：");
    // if (isNaN(age)) {
    //     alert("请输入年龄数字！");
    // } else {
    //     if (age < 0 || age > 100) {
    //         alert("请输入合法年龄！");
    //     } else {
    //         alert("您输入的年龄是：" + age);
    //     }
    // }


    // var num = prompt("请输入1-7之间的数字");
    // switch (num) {
    //     case '1':
    //         alert("星期一");
    //         break;
    //     case '2':
    //         alert("星期二");
    //         break;
    //     case '3':
    //         alert("星期三");
    //         break;
    //     case '4':
    //         alert("星期四");
    //         break;
    //     case '5':
    //         alert("星期五");
    //         break;
    //     case '6':
    //         alert("星期六");
    //         break;
    //     case '7':
    //         alert("星期七");
    //         break;
    //     default:
    //         alert("未输入指定的数字！！！");
    //         break;
    // }

    var arr = [1, 2, 3, 4, 2, 5, 6, 2, 7, 2];
    arr = arr.filter(function (item) {
        return item !== 2;
    })
    console.log(arr);


    var arr1 = ['苹果', '香蕉', '酥梨', '榴莲', '樱桃', '柿子', '葡萄', '哈密瓜', '西瓜'];
    arr1.forEach(function (item) {
        console.log(item);
    })


    function multiply() {
        var args = Array.from(arguments);

        var product = 1;
        for (var i = 0; i < args.length; i++) {
            if (typeof args[i] !== 'number') {
                continue;
            }
            product *= args[i];
        }
        return product;
    }

    var result = multiply(2, 3, 4, 5);
    document.write(result);


    var str = "abaasdffggghhjjkkgfddsssss3444343";
    console.log("字符串的长度:", str.length);

    var positions = [0, 3, 5, 9];
    var charactersAtPositions = positions.map(pos => str.charAt(pos));
    console.log("指定位置的字符:", charactersAtPositions);

    var searchChars = ['i', 'c', 'b'];
    var existence = searchChars.map(char => str.includes(char));
    console.log("指定字符是否存在:", existence);

    var replacedG = str.replace(/g/g, '22'); // 替换所有的g为22
    var replacedSS = str.replace(/ss/g, 'b'); // 替换所有的ss为b
    console.log("替换ss后的字符串:", replacedSS);

    var substring = str.slice(1, 5);
    console.log("截取的字符串:", substring);

    var charCount = {};
    for (var char of str) {
        charCount[char] = (charCount[char] || 0) + 1;
    }

    let maxChar = '';
    let maxCount = 0;
    for (var [char, count] of Object.entries(charCount)) {
        if (count > maxCount) {
            maxCount = count;
            maxChar = char;
        }
    }

    console.log("出现次数最多的字符:", maxChar, "出现的次数:", maxCount);
    var modifiedString = Array.from(str).map(char => `@${char}@`).join('');
    console.log("遍历后的字符串:", modifiedString);

    const dog = {
        name: "可可",
        breed: "金毛寻回犬", 
        age: 3, 
        color: "金色", 
        weight: 30, 
    };

        // bark: function () {
        //     console.log(`${this.name} says: 汪汪！`);
        // },

        // displayInfo: function () {
        //     console.log(`名字: ${this.name}`);
        //     console.log(`品种: ${this.breed}`);
        //     console.log(`年龄: ${this.age}岁`);
        //     console.log(`颜色: ${this.color}`);
        //     console.log(`体重: ${this.weight}公斤`);
        // }

    dog.bark(); // 输出狗叫声
    dog.displayInfo(); // 显示狗的信息




</script>

</html>